/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddPersonnel.java
 *
 * Created on Aug 3, 2011, 6:33:05 PM
 */
package invento;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JTable;

/**
 *
 * @author Kristina
 */
public class AddPersonnel extends javax.swing.JFrame {
    private Connection con;
    private Statement statement;
    private DbConnector dbConn = new DbConnector();
    private JTable tab;
    
    JFrame parent;
    /** Creates new form AddPersonnel */
    public AddPersonnel(JFrame parent, JTable table) {
        initComponents();
        this.parent = parent;
        tab = table;
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonADDpersonnel = new javax.swing.JButton();
        buttonCANCELpersonnel = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Add Personnel");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        buttonADDpersonnel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        buttonADDpersonnel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/addd.png"))); // NOI18N
        buttonADDpersonnel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        buttonADDpersonnel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonADDpersonnelActionPerformed(evt);
            }
        });
        getContentPane().add(buttonADDpersonnel, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 460, 69, 69));

        buttonCANCELpersonnel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        buttonCANCELpersonnel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/cancel2.png"))); // NOI18N
        buttonCANCELpersonnel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        buttonCANCELpersonnel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonCANCELpersonnelMouseClicked(evt);
            }
        });
        getContentPane().add(buttonCANCELpersonnel, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 460, 69, -1));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invento/addpersonneltitle.png"))); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(63, 11, -1, -1));

        jLabel14.setText("Rank:");
        getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, -1, 20));

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "P D/Gen.", "P D/DGen.", "P Dir.", "P C/Supt.", "P S/Supt.", "P Supt.", "P C/Insp", "P S/Insp.", "P Insp", "SPO4", "SPO3", "SPO2", "SPO1", "PO3", "PO2", "PO1" }));
        getContentPane().add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 180, 170, -1));

        jLabel15.setText("Last Name:");
        getContentPane().add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 260, -1, 20));
        getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 300, 171, -1));

        jLabel16.setText("First Name:");
        getContentPane().add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, -1, 20));
        getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 340, 171, 20));

        jLabel17.setText("Middle Name:");
        getContentPane().add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 340, -1, 20));
        getContentPane().add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 380, 170, -1));

        jLabel18.setText("Unit:");
        getContentPane().add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 380, -1, 20));
        getContentPane().add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 260, 171, -1));
        getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 220, 170, -1));

        jLabel7.setText("Badge Number:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 220, -1, 20));
        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 60, 170, -1));
        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 100, 170, -1));
        getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 140, 170, -1));

        jLabel1.setText("Unit");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, -1, 20));

        jLabel3.setText("Battalion");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, -1, 20));

        jLabel4.setText("Company");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, -1, 20));
        getContentPane().add(jTextField9, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 420, 170, -1));

        jLabel5.setText("Unit Code");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 420, -1, 20));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonCANCELpersonnelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonCANCELpersonnelMouseClicked
        // TODO add your handling code here:
        returntomain();
    }//GEN-LAST:event_buttonCANCELpersonnelMouseClicked

    private void buttonADDpersonnelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonADDpersonnelActionPerformed
        String Unit = "\""+jTextField1.getText()+"\", ";
 	String Bata = "\""+jTextField2.getText()+"\", ";
 	String Comp = "\""+jTextField3.getText()+"\", ";
 	String Rank = "\""+jComboBox2.getSelectedItem()+"\", ";
        String BadNo = "\""+jTextField4.getText()+"\", ";
        String nLast = "\""+jTextField5.getText()+"\", ";
 	String nFirst = "\""+jTextField6.getText()+"\", ";
 	String nMid = "\""+jTextField7.getText()+"\", ";
 	String nQuali = "\""+ jTextField8.getText()+"\", ";
        String uCode = "\""+jTextField9.getText()+"\")";

         int intTemp = 0;

        dbConn.dbConnect();
        try {
            dbConn.addPersonnelToDatabase(Unit, Bata, Comp, Rank, BadNo, nLast, nFirst, nMid, nQuali, uCode);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        dbConn.dbConnect();
        dbConn.displayPersonnel(tab);
        returntomain(); 
    }//GEN-LAST:event_buttonADDpersonnelActionPerformed

    
    public void returntomain(){
    
        this.setVisible(false);
        this.dispose();
        parent.setEnabled(true);
        parent.requestFocus();
        
    }
    
    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonADDpersonnel;
    private javax.swing.JButton buttonCANCELpersonnel;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables
}
